package com.controller;

import com.pojo.Owners;
import com.pojo.Permission;
import com.pojo.User;
import com.service.PermissionService;
import org.apache.shiro.SecurityUtils;
import org.apache.shiro.session.Session;
import org.apache.shiro.subject.Subject;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import javax.annotation.Resource;
import java.util.List;
import java.util.Map;

@Controller
public class ForwardController {

    @Resource
    private PermissionService permissionService;

    @RequestMapping("/index")
    public String index(){
        try {
            //1.获取主体对象
            Subject subject = SecurityUtils.getSubject();
            //2.通过主体对象获取用户信息
            User user = (User) subject.getPrincipal();
            //3.从subject中获取session会话
            Session session = subject.getSession();
            //4.存储
            session.setAttribute("loginUser",user);


            Map<Permission, List<Permission>> map = permissionService.createMenu();
            session.setAttribute("menuMap",map);
            System.out.println("这是controller中的map"+map);
            return "index";
        }catch (Exception e){
            System.out.println("请确认员工还是用户");
            return "login";
        }

    }



    @RequestMapping("/ownerindex")
    public String ownerindex(){
        try {
            //1.获取主体对象
            Subject subject = SecurityUtils.getSubject();
            //2.通过主体对象获取用户信息
            Owners Owners = (Owners) subject.getPrincipal();
            System.out.println(Owners);
            //3.从subject中获取session会话
            Session session = subject.getSession();
            //4.存储
            session.setAttribute("loginUser",Owners);


            Map<Permission, List<Permission>> map = permissionService.createMenu();
            session.setAttribute("menuMap",map);
            System.out.println(map);
            System.out.println("111111111111111111");
            return "ownerindex";
        }catch (Exception e){
            System.out.println("请确认员工还是用户");
            return "login";
        }

    }

}
